const path = require("path");
const urls = {
  testURL: {
    requestURL: "https://sf.21bmw.com", // 测试环境
  },
  prodURL: {
    requestURL: "https://sf.21bmw.com", // 生产环境
  },
};

const envs = ["test", "prod"];

const generateProxy = () => {
  return envs.reduce((acc, env) => {
    const basePath = `/${env}`;
    const baseRewriteKey = "^" + basePath;
    acc[basePath] = {
      target: urls[`${env}URL`].requestURL,
      pathRewrite: {
        [baseRewriteKey]: "",
      },
    };
    return acc;
  }, {});
};

const resolve = (relativePath) => {
  return path.resolve(__dirname, relativePath);
};

module.exports = {
  devServer: {
    // 代理配置
    proxy: {
      "/test/shipper/cloud/user_api": {
        target: "",
        logLevel: "debug",
        pathRewrite: {
          "^/": "",
        },
      },
      ...generateProxy(),
    },
  },
};
